package template;

/**
 * @ClassName TemplatePatternDemo
 * @Description 模板方法模式
 * @Author leejiliang
 * @DateTime 2021/2/24 14:50
 * @Version 1.0
 */
public class TemplatePatternDemo {


	public static void main(String[] args) {
		final Discount discountA = new ProductA();
		final Discount discountB = new ProductB();
		final Discount discountC = new ProductC();
		discountA.calculator();
		discountB.calculator();
		discountC.calculator();
	}

	public interface Discount {
		void calculator();
	}

	public static abstract class AbstractDiscount implements Discount {

		@Override
		public void calculator() {
			commonCalculator();
			specialCalculator();
		}

		public abstract void specialCalculator();

		private void commonCalculator() {
			System.out.println("通用处理逻辑");
		}
	}

	static class ProductA extends AbstractDiscount {

		@Override
		public void specialCalculator() {
			System.out.println("something specific A");
		}
	}

	static class ProductB extends AbstractDiscount {
		@Override
		public void specialCalculator() {
			System.out.println("something specific B");
		}
	}

	public static class ProductC extends AbstractDiscount {
		@Override
		public void specialCalculator() {
			System.out.println("something specific C");
		}
	}
}
